import {handleSql} from '../../database/mysql/index.js'


class thingBranchModelListModel {
    constructor() {
        this.tableName = 'thing_branch_model_list';
    }


    // 根据id查询某个事项分支模块
    async getBranchModelById(id){
        const sql = `SELECT * FROM ${this.tableName} 
                     WHERE id = ?`
        let result = await handleSql(sql,[id])
        return result[0]
    }

    // 根据事项模型id查询所有分支模块
    async getBranchModelsByThingModelId(thingModelId){
         const sql = `SELECT * FROM ${this.tableName} 
                     WHERE thingModelId = ?`
        let result = await handleSql(sql,[thingModelId])
        return result
    }


    // 新增事项清单模块的分支模块  —— 单条新增
    async addThingBranchModel(thingBranchModelData){
        const {thingModelId,title} = thingBranchModelData
        const sql = `INSERT INTO ${this.tableName}(thingModelId,listName)  
                     VALUES (?,?)`
        let result = await handleSql(sql,[thingModelId,title])
        if(result.affectedRows == 1){
            return true
        }else{
            return false
        }
    }
}   

export default new thingBranchModelListModel();